#include"Capsule.h"

/////////////////
//include
/////////////////
#include"Sphere.h"
#include"../CXBurst/Math.h"
/////////////////
//prottype
/////////////////

/////////////////
//const
/////////////////


Capsule::Capsule(Vector3D start,Vector3D end,float r)
{
	this->start = start;
	this->end = end;
	this->r = r;
}
Capsule::~Capsule()
{
}

CollInfo Capsule::Collision(Sphere* sphere)
{
	CollInfo info = CollInfo();
	float tmp_start_dot  = (sphere->center -start ).BitWeenRad(end - start);
	float tmp_end_dot  = (sphere->center -end ).BitWeenRad(end - start);
	float tmp_min_length = -1;
	if(abs(tmp_start_dot) > PI/2 )
	{
		tmp_min_length = (sphere->center -start).Length();
	}
	if(abs(tmp_end_dot) > PI/2)
	{
		tmp_min_length = (sphere->center -end).Length();
	}
	if(tmp_min_length < 0)
	{
		tmp_min_length = (sphere->center -start ).Cross(end - start).Length();
	}
	if(!CXBurst::IsZeroFloat(tmp_min_length,3) && tmp_min_length < r+sphere->r)
	{
		info.is_collision = true;
	}
	return info;
}
CollInfo Capsule::Collision(Capsule* capsule)
{
	CollInfo info = CollInfo();
	return info;
}